﻿
// WDDManagerDlg.cpp: 实现文件
//

#include "pch.h"
#include "framework.h"
#include "WDDManager.h"
#include "WDDManagerDlg.h"
#include "afxdialogex.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialog
{
protected:
	HICON m_hIcon;

public:
	CAboutDlg();

	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_ABOUTBOX };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(IDD_ABOUTBOX)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CWDDManagerDlg 对话框



CWDDManagerDlg::CWDDManagerDlg(CWnd* pParent /*=nullptr*/)
	: CDialog(IDD_WDDMANAGER_DIALOG, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDI_LOGO);
}

void CWDDManagerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_WORKSPACETREE, m_workspaceTree);
}

BEGIN_MESSAGE_MAP(CWDDManagerDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_DESTROY()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_ABOUTMENUITEM, &CWDDManagerDlg::OnAboutMenuItem)
	ON_COMMAND(ID_OPENWORKSPACE, &CWDDManagerDlg::OnOpenWorkspace)
	ON_COMMAND(ID_SAVEWORKSPACE, &CWDDManagerDlg::OnSaveWorkspace)
	ON_COMMAND(ID_SAVEASWORKSPACE, &CWDDManagerDlg::OnSaveAsWorkspace)
	ON_COMMAND(ID_CLOSEWORKSPACE, &CWDDManagerDlg::OnCloseWorkspace)
	ON_COMMAND(ID_CREATEWORKSPACE, &CWDDManagerDlg::OnCreateWorkspace)
	ON_COMMAND(ID_CREATEDATASOURCE, &CWDDManagerDlg::OnCreateDatasource)
	ON_COMMAND(ID_OPENDATASOURCE, &CWDDManagerDlg::OnOpenDatasource)
	ON_COMMAND(ID_SAVEDATASOURCE, &CWDDManagerDlg::OnSaveDatasource)
	ON_COMMAND(ID_CLOSEDATASOURCE, &CWDDManagerDlg::OnCloseDatasource)
	ON_COMMAND(ID_CREATEPOINTDATASET, &CWDDManagerDlg::OnCreatePointDataset)
	ON_COMMAND(ID_CREATELINEDATASET, &CWDDManagerDlg::OnCreateLineDataset)
	ON_COMMAND(ID_CREATEREGIONDATASET, &CWDDManagerDlg::OnCreateRegionDataset)
	ON_COMMAND(ID_CLOSEPOINTDATASET, &CWDDManagerDlg::OnClosePointDataset)
	ON_COMMAND(ID_CLOSELINEDATASET, &CWDDManagerDlg::OnCloseLineDataset)
	ON_COMMAND(ID_CLOSEREGIONDATASET, &CWDDManagerDlg::OnCloseRegionDataset)
	ON_COMMAND(ID_CREATEPOINT3DDATASET, &CWDDManagerDlg::OnCreatePoint3DDataset)
	ON_COMMAND(ID_CREATELINE3DDATASET, &CWDDManagerDlg::OnCreateLine3DDataset)
	ON_COMMAND(ID_CREATEREGION3DDATASET, &CWDDManagerDlg::OnCreateRegion3DDataset)
	ON_COMMAND(ID_CREATEMODELDATASET, &CWDDManagerDlg::OnCreateModelDataset)
	ON_COMMAND(ID_CLOSEPOINT3DDATASET, &CWDDManagerDlg::OnClosePoint3DDataset)
	ON_COMMAND(ID_CLOSELINE3DDATASET, &CWDDManagerDlg::OnCloseLine3DDataset)
	ON_COMMAND(ID_CLOSEREGION3DDATASET, &CWDDManagerDlg::OnCloseRegion3DDataset)
	ON_COMMAND(ID_CLOSEMODELDATASET, &CWDDManagerDlg::OnCloseModelDataset)
	ON_COMMAND(ID_CREATECADDATASET, &CWDDManagerDlg::OnCreateCADDataset)
	ON_COMMAND(ID_CLOSECADDATASET, &CWDDManagerDlg::OnCloseCADDataset)
	ON_COMMAND(ID_CREATERASTERDATASET, &CWDDManagerDlg::OnCreateRasterDataset)
	ON_COMMAND(ID_CLOSERASTERDATASET, &CWDDManagerDlg::OnCloseRasterDataset)
	ON_COMMAND(ID_CREATEIMAGEDATASET, &CWDDManagerDlg::OnCreateImageDataset)
	ON_COMMAND(ID_CLOSEIMAGEDATASET, &CWDDManagerDlg::OnCloseImageDataset)
	ON_COMMAND(ID_CREATETABLUAR, &CWDDManagerDlg::OnCreateTabluar)
	ON_COMMAND(ID_CLOSETABULAR, &CWDDManagerDlg::OnCloseTabular)
END_MESSAGE_MAP()


// CWDDManagerDlg 消息处理程序

BOOL CWDDManagerDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 将“关于...”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != nullptr)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。  当应用程序主窗口不是对话框时，框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// 加载菜单资源
	m_menu = GetMenu();
	UpdateMenuStatus();

	// 初始化工作空间树图标列表
	InitWorkspaceTreeIconList();

	return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}

/// <summary>
/// 初始化工作空间树图标列表
/// </summary>
void CWDDManagerDlg::InitWorkspaceTreeIconList()
{
	CWinApp* cApp = AfxGetApp();
	CImageList* imageList = new CImageList();
	imageList->Create(16, 16, ILC_COLOR32, 0, 1);

	HICON workspaceIcon = cApp->LoadIcon(IDI_WORKSPACEICON);
	imageList->Add(workspaceIcon);

	HICON datasourcesIcon = cApp->LoadIcon(IDI_DATASOURCEICON);
	imageList->Add(datasourcesIcon);

	HICON datasourceIcon = cApp->LoadIcon(IDI_DATASOURCEFILEICON);
	imageList->Add(datasourceIcon);

	HICON datasetPointIcon = cApp->LoadIcon(IDI_DATASETPOINTICON);
	imageList->Add(datasetPointIcon);

	HICON datasetLineIcon = cApp->LoadIcon(IDI_DATASETLINEICON);
	imageList->Add(datasetLineIcon);

	HICON datasetRegionIcon = cApp->LoadIcon(IDI_DATASETREGIONICON);
	imageList->Add(datasetRegionIcon);

	HICON datasetPoint3DIcon = cApp->LoadIcon(IDI_DATASETPOINT3DICON);
	imageList->Add(datasetPoint3DIcon);

	HICON datasetLine3DIcon = cApp->LoadIcon(IDI_DATASETLINE3DICON);
	imageList->Add(datasetLine3DIcon);

	HICON datasetRegion3DIcon = cApp->LoadIcon(IDI_DATASETREGION3DICON);
	imageList->Add(datasetRegion3DIcon);

	HICON datasetCADIcon = cApp->LoadIcon(IDI_DATASETCADICON);
	imageList->Add(datasetCADIcon);

	HICON datasetGridIcon = cApp->LoadIcon(IDI_DATASETGRIDICON);
	imageList->Add(datasetGridIcon);

	HICON datasetImageIcon = cApp->LoadIcon(IDI_DATASETIMAGEICON);
	imageList->Add(datasetImageIcon);

	HICON datasetModelIcon = cApp->LoadIcon(IDI_DATASETMODELICON);
	imageList->Add(datasetModelIcon);

	HICON datasetTabularIcon = cApp->LoadIcon(IDI_DATASETTABULARICON);
	imageList->Add(datasetTabularIcon);

	HICON datasetUnknownIcon = cApp->LoadIcon(IDI_DATASETUNKNOWNICON);
	imageList->Add(datasetUnknownIcon);

	m_workspaceTree.SetImageList(imageList, TVSIL_NORMAL);
}

/// <summary>
/// 判断当前工作空间是否存在指定类型的数据集
/// </summary>
/// <param name="workspace">工作空间</param>
/// <param name="datasetType">数据集类型</param>
/// <returns>是否存在指定类型的数据集</returns>
UGbool CWDDManagerDlg::IsExistedDataset(UGWorkspace* workspace, UGDataset::DatasetType datasetType)
{
	UGbool isExisted = FALSE;
	if (m_workspace != nullptr)
	{
		UGint datasourcesCount = m_workspace->m_DataSources.GetCount();
		if (datasourcesCount > 0)
		{
			UGString datasourceAlias;
			UGDataSource* datasource;
			for (size_t i = 0; i < datasourcesCount; i++)
			{
				if (m_workspace->m_DataSources.GetAt(i, datasourceAlias, datasource) && datasource != nullptr)
				{
					UGint datasetCount = datasource->GetDatasetCount();
					if (datasetCount > 0)
					{
						OgdcUnicodeStringArray datasetNames = datasource->GetDatasetNames();
						for (size_t j = 0; j < datasetNames.GetSize(); j++)
						{
							if (datasource->GetDataset(datasetNames.GetAt(j))->GetType() == datasetType)
							{
								isExisted = TRUE;
								break;
							}
						}
						if (isExisted)
						{
							break;
						}
					}
				}
			}
		}
	}
	return isExisted;
}

/// <summary>
/// 创建矢量数据集
/// </summary>
/// <param name="workspace">工作空间</param>
/// <param name="datasetType">数据集类型</param>
/// <param name="datasetName">数据集名称</param>
/// <returns>是否创建成功</returns>
UGbool CWDDManagerDlg::CreateDefaultDatasetVector(UGWorkspace* workspace, UGDataset::DatasetType datasetType, std::string datasetName)
{
	UGbool isCreated = FALSE;
	int datasourcesCount = workspace->m_DataSources.GetCount();
	if (datasourcesCount > 0)
	{
		UGString datasourceAlias;
		UGDataSource* datasource;
		if (workspace->m_DataSources.GetAt(0, datasourceAlias, datasource) && datasource != nullptr)
		{
			UGString strName;
			strName = GetAvailableDatasetName(datasource, strName.FromStd(datasetName));
			UGDatasetVectorInfo datasetVectorInfo;
			datasetVectorInfo.m_strName = strName;
			datasetVectorInfo.m_strTableName = strName;
			datasetVectorInfo.m_nCodecType = UGDataCodec::CodecType::envNONE;
			datasetVectorInfo.m_nSmIDType = UGDataset::SmIDType::INT64;
			datasetVectorInfo.m_nType = datasetType;
			UGDatasetVectorPtr datasetVector = datasource->CreateDatasetVector(datasetVectorInfo);
			if (datasetVector == nullptr)
			{
				return isCreated;
			}
			else
			{
				isCreated = TRUE;

				// 更新菜单状态
				UpdateMenuStatus();

				// 更新工作空间树
				UpdateWorkspaceTree();
			}
		}
	}
	return isCreated;
}

/// <summary>
/// 创建栅格数据集
/// </summary>
/// <param name="workspace">工作空间</param>
/// <param name="datasetType">数据集类型</param>
/// <param name="datasetName">数据集名称</param>
/// <returns>是否创建成功</returns>
UGbool CWDDManagerDlg::CreateDefaultDatasetRaster(UGWorkspace* workspace, UGDataset::DatasetType datasetType, std::string datasetName)
{
	UGbool isCreated = FALSE;
	int datasourcesCount = workspace->m_DataSources.GetCount();
	if (datasourcesCount > 0)
	{
		UGString datasourceAlias;
		UGDataSource* datasource;
		if (workspace->m_DataSources.GetAt(0, datasourceAlias, datasource) && datasource != nullptr)
		{
			UGString strName;
			strName = GetAvailableDatasetName(datasource, strName.FromStd(datasetName));
			UGDatasetRasterInfo datasetRasterInfo;
			datasetRasterInfo.m_strName = strName;
			datasetRasterInfo.m_strTableName = strName;
			datasetRasterInfo.m_rc2Bounds = UGRect2D(-200.0, -200.0, 200.0, 200.0);
			datasetRasterInfo.m_eBlockSize = UGDatasetRasterInfo::IBSizeOption::IBS_64;
			datasetRasterInfo.m_nHeight = 800;
			datasetRasterInfo.m_nWidth = 800;
			datasetRasterInfo.m_nType = datasetType;
			datasetRasterInfo.SetPixelFormat(OGDC::PixelFormat::IPF_DOUBLE);
			datasetRasterInfo.SetNoValue(-9999.0);

			UGBandInfo bandInfo;
			bandInfo.m_bAvail = TRUE;
			bandInfo.m_dMaxZ = 10000.0;
			bandInfo.m_dMinZ = -1000.0;
			bandInfo.m_nBandID = 1;
			bandInfo.m_nIndex = 1;
			bandInfo.m_nCodecType = UGDataCodec::CodecType::enrNONE;
			bandInfo.SetPixelFormat(OGDC::PixelFormat::IPF_DOUBLE);
			bandInfo.SetNoValue(-9999.0);
			datasetRasterInfo.Add(bandInfo);
			UGDatasetRasterPtr datasetRaster = datasource->CreateDatasetRaster(datasetRasterInfo);
			if (datasetRaster == nullptr)
			{
				return isCreated;
			}
			else
			{
				isCreated = TRUE;

				// 更新菜单状态
				UpdateMenuStatus();

				// 更新工作空间树
				UpdateWorkspaceTree();
			}
		}
	}
	return isCreated;
}

/// <summary>
/// 关闭数据集
/// </summary>
/// <param name="workspace">工作空间</param>
/// <param name="datasetType">数据集类型</param>
/// <returns>是否关闭成功</returns>
UGbool CWDDManagerDlg::CloseDataset(UGWorkspace* workspace, UGDataset::DatasetType datasetType)
{
	if (IsExistedDataset(workspace, datasetType))
	{
		UGbool isDeleted = FALSE;
		UGint datasourcesCount = workspace->m_DataSources.GetCount();
		for (size_t i = 0; i < datasourcesCount; i++)
		{
			UGString datasourceAlias;
			UGDataSource* datasource;
			if (workspace->m_DataSources.GetAt(0, datasourceAlias, datasource) && datasource != nullptr)
			{
				UGint datasetCount = datasource->GetDatasetCount();
				OgdcUnicodeStringArray datasetNames = datasource->GetDatasetNames();
				for (size_t j = 0; j < datasetNames.GetSize(); j++)
				{
					UGDatasetPtr dataset = datasource->GetDataset(datasetNames.GetAt(j));
					if (dataset->GetType() == datasetType)
					{
						dataset->Close();
						if (!datasource->DeleteDataset(dataset->GetName()) || !datasource->SaveInfo() || !datasource->Compact(TRUE))
						{
							return isDeleted;
						}
						else
						{
							isDeleted = TRUE;

							// 更新菜单状态
							UpdateMenuStatus();

							// 更新工作空间树
							UpdateWorkspaceTree();

							break;
						}
					}
				}
			}
			if (isDeleted)
			{
				break;
			}
		}
		return isDeleted;
	}
}

/// <summary>
/// 更新菜单项状态
/// </summary>
void CWDDManagerDlg::UpdateMenuStatus()
{
	UINT workspaceStatus = m_workspace == nullptr ? MF_DISABLED : MF_ENABLED;
	UINT datasourceStatus = workspaceStatus == MF_ENABLED && m_workspace->m_DataSources.GetCount() > 0 ? MF_ENABLED : MF_DISABLED;
	UINT closePointDatasetStatus = IsExistedDataset(m_workspace, UGDataset::DatasetType::Point) ? MF_ENABLED : MF_DISABLED;
	UINT closeLineDatasetStatus = IsExistedDataset(m_workspace, UGDataset::DatasetType::Line) ? MF_ENABLED : MF_DISABLED;;
	UINT closeRegionDatasetStatus = IsExistedDataset(m_workspace, UGDataset::DatasetType::Region) ? MF_ENABLED : MF_DISABLED;
	UINT closePoint3DDatasetStatus = IsExistedDataset(m_workspace, UGDataset::DatasetType::PointZ) ? MF_ENABLED : MF_DISABLED;
	UINT closeLine3DDatasetStatus = IsExistedDataset(m_workspace, UGDataset::DatasetType::LineZ) ? MF_ENABLED : MF_DISABLED;
	UINT closeRegion3DDatasetStatus = IsExistedDataset(m_workspace, UGDataset::DatasetType::RegionZ) ? MF_ENABLED : MF_DISABLED;
	UINT closeModelDatasetStatus = IsExistedDataset(m_workspace, UGDataset::DatasetType::Model) ? MF_ENABLED : MF_DISABLED;
	UINT closeCADDatasetStatus = IsExistedDataset(m_workspace, UGDataset::DatasetType::CAD) ? MF_ENABLED : MF_DISABLED;
	UINT closeRasterDatasetStatus = IsExistedDataset(m_workspace, UGDataset::DatasetType::Grid) ? MF_ENABLED : MF_DISABLED;
	UINT closeImageDatasetStatus = IsExistedDataset(m_workspace, UGDataset::DatasetType::Image) ? MF_ENABLED : MF_DISABLED;
	UINT closeTabularDatasetStatus = IsExistedDataset(m_workspace, UGDataset::DatasetType::Tabular) ? MF_ENABLED : MF_DISABLED;

	// 工作空间菜单栏
	m_menu->EnableMenuItem(ID_SAVEWORKSPACE, workspaceStatus);
	m_menu->EnableMenuItem(ID_SAVEASWORKSPACE, workspaceStatus);
	m_menu->EnableMenuItem(ID_CLOSEWORKSPACE, workspaceStatus);

	// 数据源菜单栏
	m_menu->EnableMenuItem(ID_CREATEDATASOURCE, workspaceStatus);
	m_menu->EnableMenuItem(ID_OPENDATASOURCE, workspaceStatus);
	m_menu->EnableMenuItem(ID_SAVEDATASOURCE, datasourceStatus);
	m_menu->EnableMenuItem(ID_CLOSEDATASOURCE, datasourceStatus);

	// 数据集菜单栏

	// 新建
	m_menu->EnableMenuItem(ID_CREATEPOINTDATASET, datasourceStatus);
	m_menu->EnableMenuItem(ID_CREATELINEDATASET, datasourceStatus);
	m_menu->EnableMenuItem(ID_CREATEREGIONDATASET, datasourceStatus);
	m_menu->EnableMenuItem(ID_CREATEPOINT3DDATASET, datasourceStatus);
	m_menu->EnableMenuItem(ID_CREATELINE3DDATASET, datasourceStatus);
	m_menu->EnableMenuItem(ID_CREATEREGION3DDATASET, datasourceStatus);
	m_menu->EnableMenuItem(ID_CREATEMODELDATASET, datasourceStatus);
	m_menu->EnableMenuItem(ID_CREATECADDATASET, datasourceStatus);
	m_menu->EnableMenuItem(ID_CREATERASTERDATASET, datasourceStatus);
	m_menu->EnableMenuItem(ID_CREATEIMAGEDATASET, datasourceStatus);
	m_menu->EnableMenuItem(ID_CREATETABLUAR, datasourceStatus);

	// 关闭
	m_menu->EnableMenuItem(ID_CLOSEPOINTDATASET, closePointDatasetStatus);
	m_menu->EnableMenuItem(ID_CLOSELINEDATASET, closeLineDatasetStatus);
	m_menu->EnableMenuItem(ID_CLOSEREGIONDATASET, closeRegionDatasetStatus);
	m_menu->EnableMenuItem(ID_CLOSEPOINT3DDATASET, closePoint3DDatasetStatus);
	m_menu->EnableMenuItem(ID_CLOSELINE3DDATASET, closeLine3DDatasetStatus);
	m_menu->EnableMenuItem(ID_CLOSEREGION3DDATASET, closeRegion3DDatasetStatus);
	m_menu->EnableMenuItem(ID_CLOSEMODELDATASET, closeModelDatasetStatus);
	m_menu->EnableMenuItem(ID_CLOSECADDATASET, closeCADDatasetStatus);
	m_menu->EnableMenuItem(ID_CLOSERASTERDATASET, closeRasterDatasetStatus);
	m_menu->EnableMenuItem(ID_CLOSEIMAGEDATASET, closeImageDatasetStatus);
	m_menu->EnableMenuItem(ID_CLOSETABULAR, closeTabularDatasetStatus);
}

/// <summary>
/// 更新工作空间树
/// </summary>
void CWDDManagerDlg::UpdateWorkspaceTree()
{
	// 清空当前工作空间树节点
	m_workspaceTree.DeleteAllItems();

	if (m_workspace != nullptr)
	{
		// 初始化根节点
		HTREEITEM workspaceNode = m_workspaceTree.InsertItem(m_workspace->GetCaption(), 0, 0);
		HTREEITEM datasourcesNode = m_workspaceTree.InsertItem(_T("数据源"), 1, 1, workspaceNode);

		// 加载当前工作空间
		UGint datasourcesCount = m_workspace->m_DataSources.GetCount();
		for (size_t i = 0; i < datasourcesCount; i++)
		{
			// 加载数据源
			UGString datasourceAlias;
			UGDataSource* datasource;
			if (m_workspace->m_DataSources.GetAt(i, datasourceAlias, datasource) && datasource != nullptr)
			{
				HTREEITEM datasourceNode = m_workspaceTree.InsertItem(datasourceAlias, 2, 2, datasourcesNode);

				// 加载数据集
				UGint datasetCount = datasource->GetDatasetCount();
				if (datasetCount > 0)
				{
					OgdcUnicodeStringArray datasetNames = datasource->GetDatasetNames();
					OgdcArray<int> datasetIDArray;
					for (size_t j = 0; j < datasetNames.GetSize(); j++)
					{
						UGString datasetName = datasetNames.GetAt(j);
						UGDatasetPtr dataset = datasource->GetDataset(datasetName);
						UGint datasetID = dataset->GetID();
						if (!datasetIDArray.Find(datasetID))
						{
							datasetIDArray.Add(datasetID);
						}
					}

					// 根据数据集的创建时间排序
					sort(datasetIDArray.begin(), datasetIDArray.end());

					for (size_t j = 0; j < datasetCount; j++)
					{
						UGDatasetPtr dataset = datasource->GetDatasetByID(datasetIDArray.GetAt(j));
						UGDataset::DatasetType datasetType = dataset->GetType();
						int datasetIconIndex = GetDatasetIconIndex(datasetType);
						HTREEITEM datasetNode = m_workspaceTree.InsertItem(dataset->GetName(), datasetIconIndex, datasetIconIndex, datasourceNode);
					}

					datasetIDArray.RemoveAll();
				}

				m_workspaceTree.Expand(datasourceNode, TVE_EXPAND);
			}
		}

		m_workspaceTree.Expand(datasourcesNode, TVE_EXPAND);
		m_workspaceTree.Expand(workspaceNode, TVE_EXPAND);
	}
}

/// <summary>
/// 根据数据集类型获取图标索引
/// </summary>
/// <param name="datasetType">数据集类型</param>
/// <returns>图标索引</returns>
int CWDDManagerDlg::GetDatasetIconIndex(UGDataset::DatasetType datasetType)
{
	int index = 0;
	switch (datasetType)
	{
	case UGC::UGDataset::Point:
		index = 3;
		break;
	case UGC::UGDataset::Line:
		index = 4;
		break;
	case UGC::UGDataset::Region:
		index = 5;
		break;
	case UGC::UGDataset::PointZ:
		index = 6;
		break;
	case UGC::UGDataset::LineZ:
		index = 7;
		break;
	case UGC::UGDataset::RegionZ:
		index = 8;
		break;
	case UGC::UGDataset::CAD:
		index = 9;
		break;
	case UGC::UGDataset::Grid:
		index = 10;
		break;
	case UGC::UGDataset::Image:
		index = 11;
		break;
	case UGC::UGDataset::Model:
		index = 12;
		break;
	case UGC::UGDataset::Tabular:
		index = 13;
		break;
	default:
		index = 14;
		break;
	}
	return index;
}

/// <summary>
/// 获取可用的数据集名称
/// </summary>
/// <param name="datasource">数据源</param>
/// <param name="datasetName">数据集名称</param>
/// <returns>可用的数据集名称</returns>
UGString CWDDManagerDlg::GetAvailableDatasetName(UGDataSource* datasource, UGString datasetName)
{
	int nameSuffix = 1;
	UGString resultDatasetName = datasetName;
	UGToolkit::InvalidNameState invalidNameState;
	while (!datasource->IsAvailableDatasetName(resultDatasetName, invalidNameState))
	{
		resultDatasetName = datasetName + _T("_") + nameSuffix++;
	}
	return resultDatasetName;
}

/// <summary>
/// 根据文件型工作空间文件后缀名获取工作空间类型
/// </summary>
/// <param name="workspaceFileExt">文件型工作空间文件后缀名</param>
/// <returns>工作空间类型</returns>
UGint CWDDManagerDlg::GetWorkspaceType(CString workspaceFileExt)
{
	return workspaceFileExt == "smwu" ? UGWorkspace::UGWorkspaceType::WS_Version_SMWU : UGWorkspace::UGWorkspaceType::WS_Version_SXWU;
}

void CWDDManagerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}


void CWDDManagerDlg::OnDestroy()
{
	CDialog::OnDestroy();

	CWDDManagerDlg::OnCloseWorkspace();
}

// 如果向对话框添加最小化按钮，则需要下面的代码
//  来绘制该图标。  对于使用文档/视图模型的 MFC 应用程序，
//  这将由框架自动完成。

void CWDDManagerDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CWDDManagerDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

/// <summary>
/// 弹出程序关于信息对话框
/// </summary>
void CWDDManagerDlg::OnAboutMenuItem()
{
	try
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
		delete dlgAbout;
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 新建工作空间
/// </summary>
void CWDDManagerDlg::OnCreateWorkspace()
{
	try
	{
		if (m_workspace != nullptr)
		{
			if (m_workspace->IsModified())
			{
				if (IDOK == MessageBox(_T("当前工作空间尚未保存，是否保存工作空间？"), _T("保存工作空间"), MB_OKCANCEL))
				{
					if (!m_workspace->Save())
					{
						MessageBox(_T("保存工作空间失败！建议检查 iObjects C++ 组件日志查看异常详情。"), _T("保存工作空间"), MB_OK);
					}

					m_workspace->Close();
					m_workspace = nullptr;
				}
			}
		}

		UGString tempWorkspaceName = _U("工作空间");
		if (m_tempWorkspacePath.IsEmpty())
		{
			wchar_t tempPath[MAX_PATH];
			GetTempPath(MAX_PATH, tempPath);
			m_tempWorkspacePath = tempPath;
			m_tempWorkspacePath += tempWorkspaceName;
			m_tempWorkspacePath += _U(".smwu");
		}

		m_workspace = new UGWorkspace();
		UGWorkspaceConnection workspaceConnection = UGWorkspaceConnection();
		workspaceConnection.m_strServer = m_tempWorkspacePath;
		workspaceConnection.m_nVersion = UG_WORKSPACE_VERSION_20120328;
		workspaceConnection.m_nWorkspaceType = UGWorkspace::UGWorkspaceType::WS_Version_SMWU;
		workspaceConnection.m_bFailIfExists = false;
		m_workspace->SaveAs(workspaceConnection);
		m_workspace->SetName(tempWorkspaceName);
		m_workspace->SetCaption(tempWorkspaceName);

		// 更新菜单状态
		UpdateMenuStatus();

		// 更新工作空间树
		UpdateWorkspaceTree();
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 打开工作空间
/// </summary>
void CWDDManagerDlg::OnOpenWorkspace()
{
	try
	{
		CFileDialog fileDialog(TRUE, _T(""), _T(""), OFN_HIDEREADONLY | OFN_READONLY | OFN_NOCHANGEDIR, m_workspaceFilter, this);
		if (IDOK == fileDialog.DoModal())
		{
			CString workspaceFilePath = fileDialog.GetPathName();
			CString workspaceFileExt = fileDialog.GetFileExt();
			CString workspaceFileName = fileDialog.GetFileTitle();
			delete fileDialog;

			// 构建工作空间连接信息
			UGWorkspaceConnection workspaceConnection = UGWorkspaceConnection();
			workspaceConnection.m_strServer = workspaceFilePath;
			workspaceConnection.m_nVersion = UG_WORKSPACE_VERSION_20120328;
			workspaceConnection.m_nWorkspaceType = GetWorkspaceType(workspaceFileExt);
			workspaceConnection.m_bFailIfExists = false;
			workspaceConnection.m_strWorkspaceName = workspaceFileName;

			// 打开工作空间
			m_workspace = new UGWorkspace();
			if (!m_workspace->Open(workspaceConnection))
			{
				MessageBox(_T("打开工作空间失败！建议检查工作空间文件是否存在异常。\r\n工作空间文件路径：") + workspaceFilePath, _T("打开工作空间"), MB_OK);
				return;
			}

			m_workspace->SetName(workspaceConnection.m_strWorkspaceName);
			m_workspace->SetCaption(workspaceConnection.m_strWorkspaceName);

			// 更新菜单状态
			UpdateMenuStatus();

			// 更新工作空间树
			UpdateWorkspaceTree();
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 保存工作空间
/// </summary>
void CWDDManagerDlg::OnSaveWorkspace()
{
	try
	{
		if (m_workspace == nullptr)
		{
			MessageBox(_T("当前无可用的工作空间！"), _T("保存工作空间"), MB_OK);
		}
		else if (!m_workspace->Save())
		{
			MessageBox(_T("保存工作空间失败！建议检查 iObjects C++ 组件日志查看异常详情。"), _T("保存工作空间"), MB_OK);
		}
		else
		{
			// 更新菜单状态
			UpdateMenuStatus();
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 另存工作空间
/// </summary>
void CWDDManagerDlg::OnSaveAsWorkspace()
{
	try
	{
		CFileDialog fileDialog(FALSE, _T(""), _T(""), OFN_HIDEREADONLY | OFN_READONLY | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT, m_workspaceFilter, this);
		if (IDOK == fileDialog.DoModal())
		{
			CString workspaceFilePath = fileDialog.GetPathName();
			CString workspaceFileExt = fileDialog.GetFileExt();
			CString workspaceFileName = fileDialog.GetFileTitle();
			delete fileDialog;

			// 构建工作空间连接信息
			UGWorkspaceConnection workspaceConnection = UGWorkspaceConnection();
			workspaceConnection.m_strServer = workspaceFilePath;
			workspaceConnection.m_nVersion = UG_WORKSPACE_VERSION_20120328;
			workspaceConnection.m_nWorkspaceType = GetWorkspaceType(workspaceFileExt);
			workspaceConnection.m_bFailIfExists = false;
			workspaceConnection.m_strWorkspaceName = workspaceFileName;

			m_workspace->SetName(workspaceConnection.m_strWorkspaceName);
			m_workspace->SetCaption(workspaceConnection.m_strWorkspaceName);

			// 另存工作空间
			if (!m_workspace->SaveAs(workspaceConnection))
			{
				MessageBox(_T("另存工作空间失败！建议检查 iObjects C++ 组件日志查看异常详情。"), _T("另存工作空间"), MB_OK);
			}
			else
			{
				m_tempWorkspacePath.Empty();
			}

			// 更新菜单状态
			UpdateMenuStatus();

			// 更新工作空间树
			UpdateWorkspaceTree();
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 关闭工作空间
/// </summary>
void CWDDManagerDlg::OnCloseWorkspace()
{
	try
	{
		if (m_workspace != nullptr)
		{
			m_workspace->Close();
			delete m_workspace;
			m_workspace = nullptr;
		}

		if (!m_tempWorkspacePath.IsEmpty())
		{
			CFile tempWorkspaceFile;
			tempWorkspaceFile.Remove(m_tempWorkspacePath);
			m_tempWorkspacePath.Empty();
		}

		// 更新菜单状态
		UpdateMenuStatus();

		// 更新工作空间树
		UpdateWorkspaceTree();
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 新建数据源
/// </summary>
void CWDDManagerDlg::OnCreateDatasource()
{
	try
	{
		CFileDialog fileDialog(FALSE, _T(".udbx"), _T(""), OFN_HIDEREADONLY | OFN_READONLY | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT, m_datasourceFilter, this);
		if (IDOK == fileDialog.DoModal())
		{
			CString filePath = fileDialog.GetPathName();
			CString fileTitle = fileDialog.GetFileTitle();
			delete fileDialog;

			UGDataSource* datasource = UGDataSourceManager::CreateDataSource(UGEngineType::Spatialite);
			UGDsConnection& dsConn = datasource->GetConnectionInfo();
			dsConn.m_strServer = filePath;
			dsConn.m_strAlias = fileTitle;
			dsConn.m_nType = UGEngineType::Spatialite;

			if (!datasource->Create())
			{
				datasource->Close();
				delete datasource;
				MessageBox(_T("新建 UDBX 数据源失败！"), _T("新建数据源"), MB_OK);
				return;
			}
			else
			{
				if (!m_workspace->m_DataSources.Insert(dsConn.m_strAlias, datasource) || !m_workspace->Save())
				{
					MessageBox(_T("将新建 UDBX 数据源添加到当前工作空间失败！"), _T("新建数据源"), MB_OK);
				}
				else
				{
					// 更新菜单状态
					UpdateMenuStatus();

					// 更新工作空间树
					UpdateWorkspaceTree();
				}
			}
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 打开数据源
/// </summary>
void CWDDManagerDlg::OnOpenDatasource()
{
	try
	{
		CFileDialog fileDialog(TRUE, _T(".udbx"), _T(""), OFN_HIDEREADONLY | OFN_READONLY | OFN_NOCHANGEDIR, m_datasourceFilter, this);
		if (IDOK == fileDialog.DoModal())
		{
			CString filePath = fileDialog.GetPathName();
			CString fileTitle = fileDialog.GetFileTitle();
			delete fileDialog;

			UGDataSource* datasource = UGDataSourceManager::CreateDataSource(UGEngineType::Spatialite);
			UGDsConnection& dsConn = datasource->GetConnectionInfo();
			dsConn.m_strServer = filePath;
			dsConn.m_strAlias = fileTitle;
			dsConn.m_nType = UGEngineType::Spatialite;

			if (!datasource->Open())
			{
				datasource->Close();
				delete datasource;
				MessageBox(_T("打开 UDBX 数据源失败！\r\nUDBX 文件路径：") + filePath, _T("打开数据源"), MB_OK);
				return;
			}
			else
			{
				if (!m_workspace->m_DataSources.Insert(dsConn.m_strAlias, datasource) || !m_workspace->Save())
				{
					MessageBox(_T("将打开 UDBX 数据源添加到当前工作空间失败！"), _T("打开数据源"), MB_OK);
				}
				else
				{
					// 更新菜单状态
					UpdateMenuStatus();

					// 更新工作空间树
					UpdateWorkspaceTree();
				}
			}
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 保存数据源
/// </summary>
void CWDDManagerDlg::OnSaveDatasource()
{
	try
	{
		int datasourcesCount = m_workspace->m_DataSources.GetCount();
		if (datasourcesCount > 0)
		{
			UGString datasourceAlias;
			UGDataSource* datasource;
			if (m_workspace->m_DataSources.GetAt(0, datasourceAlias, datasource) && datasource != nullptr && datasource->IsModified())
			{
				if (!datasource->SaveInfo())
				{
					MessageBox(_T("保存数据源失败！"), _T("保存数据源"), MB_OK);
				}
				else
				{
					// 更新菜单状态
					UpdateMenuStatus();
				}
			}
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 关闭数据源
/// </summary>
void CWDDManagerDlg::OnCloseDatasource()
{
	try
	{
		int datasourcesCount = m_workspace->m_DataSources.GetCount();
		if (datasourcesCount > 0)
		{
			UGDataSource* datasource = m_workspace->m_DataSources.RemoveAt(0);
			if (datasource == nullptr)
			{
				MessageBox(_T("从工作空间移除数据源失败！"), _T("关闭数据源"), MB_OK);
			}
			else
			{
				datasource->Close();
				delete datasource;
				OnSaveWorkspace();

				// 更新菜单状态
				UpdateMenuStatus();

				// 更新工作空间树
				UpdateWorkspaceTree();
			}
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 新建二维矢量点数据集
/// </summary>
void CWDDManagerDlg::OnCreatePointDataset()
{
	try
	{
		if (!CreateDefaultDatasetVector(m_workspace, UGDataset::DatasetType::Point, std::string("Point")))
		{
			MessageBox(_T("新建二维矢量点数据集失败！"), _T("新建数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 新建二维矢量线数据集
/// </summary>
void CWDDManagerDlg::OnCreateLineDataset()
{
	try
	{
		if (!CreateDefaultDatasetVector(m_workspace, UGDataset::DatasetType::Line, std::string("Line")))
		{
			MessageBox(_T("新建二维矢量线数据集失败！"), _T("新建数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 新建二维矢量面数据集
/// </summary>
void CWDDManagerDlg::OnCreateRegionDataset()
{
	try
	{
		if (!CreateDefaultDatasetVector(m_workspace, UGDataset::DatasetType::Region, std::string("Region")))
		{
			MessageBox(_T("新建二维矢量线数据集失败！"), _T("新建数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 新建三维矢量点数据集
/// </summary>
void CWDDManagerDlg::OnCreatePoint3DDataset()
{
	try
	{
		if (!CreateDefaultDatasetVector(m_workspace, UGDataset::DatasetType::PointZ, std::string("Point3D")))
		{
			MessageBox(_T("新建三维矢量点数据集失败！"), _T("新建数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 新建三维矢量线数据集
/// </summary>
void CWDDManagerDlg::OnCreateLine3DDataset()
{
	try
	{
		if (!CreateDefaultDatasetVector(m_workspace, UGDataset::DatasetType::LineZ, std::string("Line3D")))
		{
			MessageBox(_T("新建三维矢量线数据集失败！"), _T("新建数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 新建三维矢量面数据集
/// </summary>
void CWDDManagerDlg::OnCreateRegion3DDataset()
{
	try
	{
		if (!CreateDefaultDatasetVector(m_workspace, UGDataset::DatasetType::RegionZ, std::string("Region3D")))
		{
			MessageBox(_T("新建三维矢量面数据集失败！"), _T("新建数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 新建模型数据集
/// </summary>
void CWDDManagerDlg::OnCreateModelDataset()
{
	try
	{
		if (!CreateDefaultDatasetVector(m_workspace, UGDataset::DatasetType::Model, std::string("Model")))
		{
			MessageBox(_T("新建模型数据集失败！"), _T("新建数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 新建CAD数据集
/// </summary>
void CWDDManagerDlg::OnCreateCADDataset()
{
	try
	{
		if (!CreateDefaultDatasetVector(m_workspace, UGDataset::DatasetType::CAD, std::string("CAD")))
		{
			MessageBox(_T("新建 CAD 数据集失败！"), _T("新建数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 新建栅格数据集
/// </summary>
void CWDDManagerDlg::OnCreateRasterDataset()
{
	try
	{
		if (!CreateDefaultDatasetRaster(m_workspace, UGDataset::DatasetType::Grid, std::string("Raster")))
		{
			MessageBox(_T("新建栅格数据集失败！"), _T("新建数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 新建影像数据集
/// </summary>
void CWDDManagerDlg::OnCreateImageDataset()
{
	try
	{
		if (!CreateDefaultDatasetRaster(m_workspace, UGDataset::DatasetType::Image, std::string("Image")))
		{
			MessageBox(_T("新建影像数据集失败！"), _T("新建数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 新建属性表
/// </summary>
void CWDDManagerDlg::OnCreateTabluar()
{
	try
	{
		if (!CreateDefaultDatasetVector(m_workspace, UGDataset::DatasetType::Tabular, std::string("Tabular")))
		{
			MessageBox(_T("新建属性表失败！"), _T("新建数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 关闭二维矢量点数据集
/// </summary>
void CWDDManagerDlg::OnClosePointDataset()
{
	try
	{
		if (!CloseDataset(m_workspace, UGDataset::DatasetType::Point))
		{
			MessageBox(_T("关闭二维矢量点数据集失败！"), _T("关闭数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 关闭二维矢量线数据集
/// </summary>
void CWDDManagerDlg::OnCloseLineDataset()
{
	try
	{
		if (!CloseDataset(m_workspace, UGDataset::DatasetType::Line))
		{
			MessageBox(_T("关闭二维矢量线数据集失败！"), _T("关闭数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 关闭二维矢量面数据集
/// </summary>
void CWDDManagerDlg::OnCloseRegionDataset()
{
	try
	{
		if (!CloseDataset(m_workspace, UGDataset::DatasetType::Region))
		{
			MessageBox(_T("关闭二维矢量面数据集失败！"), _T("关闭数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 关闭三维矢量点数据集
/// </summary>
void CWDDManagerDlg::OnClosePoint3DDataset()
{
	try
	{
		if (!CloseDataset(m_workspace, UGDataset::DatasetType::PointZ))
		{
			MessageBox(_T("关闭三维矢量点数据集失败！"), _T("关闭数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 关闭三维矢量线数据集
/// </summary>
void CWDDManagerDlg::OnCloseLine3DDataset()
{
	try
	{
		if (!CloseDataset(m_workspace, UGDataset::DatasetType::LineZ))
		{
			MessageBox(_T("关闭三维矢量线数据集失败！"), _T("关闭数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 关闭三维矢量面数据集
/// </summary>
void CWDDManagerDlg::OnCloseRegion3DDataset()
{
	try
	{
		if (!CloseDataset(m_workspace, UGDataset::DatasetType::RegionZ))
		{
			MessageBox(_T("关闭三维矢量面数据集失败！"), _T("关闭数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 关闭模型数据集
/// </summary>
void CWDDManagerDlg::OnCloseModelDataset()
{
	try
	{
		if (!CloseDataset(m_workspace, UGDataset::DatasetType::Model))
		{
			MessageBox(_T("关闭模型数据集失败！"), _T("关闭数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 关闭 CAD 数据集
/// </summary>
void CWDDManagerDlg::OnCloseCADDataset()
{
	try
	{
		if (!CloseDataset(m_workspace, UGDataset::DatasetType::CAD))
		{
			MessageBox(_T("关闭 CAD 数据集失败！"), _T("关闭数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 关闭栅格数据集
/// </summary>
void CWDDManagerDlg::OnCloseRasterDataset()
{
	try
	{
		if (!CloseDataset(m_workspace, UGDataset::DatasetType::Grid))
		{
			MessageBox(_T("关闭栅格数据集失败！"), _T("关闭数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 关闭影像数据集
/// </summary>
void CWDDManagerDlg::OnCloseImageDataset()
{
	try
	{
		if (!CloseDataset(m_workspace, UGDataset::DatasetType::Image))
		{
			MessageBox(_T("关闭影像数据集失败！"), _T("关闭数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}

/// <summary>
/// 关闭属性表
/// </summary>
void CWDDManagerDlg::OnCloseTabular()
{
	try
	{
		if (!CloseDataset(m_workspace, UGDataset::DatasetType::Tabular))
		{
			MessageBox(_T("关闭属性表失败！"), _T("关闭数据集"), MB_OK);
		}
	}
	catch (exception e)
	{
		cout << e.what() << endl;
	}
}
